<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>e网批发管理后台</title>
  <?php include("common/conn.php");
if($_SESSION['userid']==""){echo "<script>window.location.href='login.php';</script>";} 
  if($_GET['del']=="ok")
  {
    $area = array(); 
    $area= $_POST['checkbox'];

    foreach ($area as $k=>$v)
    {
      $srat1=mysql_query("DELETE FROM shop where shopid='".$v."'");
    }

  }

  if ($_GET['cancel']='ok') {
    $srat1=mysql_query("DELETE FROM ad where id='".$_GET['id']."'");
  }

// 营业与否
if ($_REQUEST[open]!='') {
  mysql_query("UPDATE shop set open=".$_REQUEST[open]." where shopid=".$_REQUEST[shopid]);
  echo "<script>window.location.href='jingxuan_shop.php'</script>";
}
// 营业与否 end

  // 一键审核通过
  if ($_REQUEST['act'] == 'passall') {
      $shopids = $_REQUEST['shopids'];
      $query = mysql_query("UPDATE shop set `check` = 1 where shopid in (".$shopids.")");
      echo "<script>alert('修改成功');window.location.href='jingxuan_shop.php'</script>";
  }
  // 一键审核通过 end

// 是否通过审核
if ($_REQUEST[check]!='') {
  mysql_query("UPDATE shop set `check`=".$_REQUEST[check]." where shopid=".$_REQUEST[shopid]);
  echo "<script>window.location.href='jingxuan_shop.php'</script>";
}
// 是否通过审核 end
// 选为特价商家
  // if ($_REQUEST[recommend]=='ok') {
  //   mysql_query("UPDATE shop set recommend=1 where shopid=".$_REQUEST[shopid]."");
  //   echo "<script>window.location.href='jingxuan_shop.php'</script>";
  // }elseif ($_REQUEST[recommend]=='no') {
  //   mysql_query("UPDATE shop set recommend=0 where shopid=".$_REQUEST[shopid]."");
  //   echo "<script>window.location.href='jingxuan_shop.php'</script>";
  // }
// 选为特价商家 end


// 查询全部社区
$query = mysql_query("select * from city");
while ($row = mysql_fetch_assoc($query)) {
  $citys[] = $row;
}
// 查询全部社区 end

// 查询全部分类
$query = mysql_query("select * from categroy");
while ($row = mysql_fetch_assoc($query)) {
  $categroys[] = $row;
}
// 查询全部分类 end
  ?>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <link href="css/styles.css" rel="stylesheet" type="text/css" />
  <link href="css/style2.css" rel="stylesheet" type="text/css" />
  <script type="text/JavaScript">
    <!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<!-- 13924075438 -->
  <!--header-->
  <?php include("common/header.php");?>
  <!--header end-->


  <!-- staqrt subnav -->
  <div id="sub_nav">

    <div id="subnav_wrap" class="container_12">
      <div id="subnav" class=" grid_12">
      </div>

    </div>


  </div>
  <div class="container_12" style="background: #fff; border:0px;">

    <form action="?" method="post">
      <label>市场</label>
      <select class="select citys">
        <option value="0">全部市场</option>
        <?php foreach ($citys as $v) { ?>
        <option <?php if ($_REQUEST[cityid]==$v[id]) { ?> selected <?php } ?> value="<?php echo $v[id]; ?>"><?php echo $v[name]; ?></option>
        <?php } ?>
      </select>

      <label>分类</label>
      <select class="select categroys">
        <option value="0">全部分类</option>
        <?php foreach ($categroys as $v) { ?>
        <option <?php if ($_REQUEST[categroyid]==$v[cateid]) { ?> selected <?php } ?> value="<?php echo $v[cateid]; ?>"><?php echo $v[name]; ?></option>
        <?php } ?>
      </select>

      <input  type="text" placeholder="厂商关键字/厂商编码" class="text" value=""name="keywords"/>

      <input name="" type="submit" class="submit" value="搜索厂商" />
      <input type="button" class="submit" value="新增厂商" onclick="add();">
    </form>


  </div>
    <form id="form" action="?del=ok&shopid=<?php  echo $_REQUEST[shopid]; ?>" method="post">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th width="5%" scope="col">
            <input type="checkbox" name="checkbox" id="checkbox" class="checkall" /><label for="checkbox"></label></th>
            <th width="8%" scope="col">是否通过审核</th>
            <th width="5%" scope="col">审核状态</th>
            <th  scope="col">精选广告图片</th>
            <th width="8%" scope="col">登录帐号</th>
            <th width="8%" scope="col">名称</th>
            <th width="8%" scope="col">厂商代码</th>
            <th width="8%" scope="col">地址</th>
            <th width="6%" scope="col">市场</th>
            <th width="5%" scope="col">分类</th>
            <th width="3%" scope="col">商品</th>
            <th width="8%" scope="col">推荐商家</th>
            <th scope="col">操作</th>
          </tr>

          <?php 
          mysql_query('SET NAMES UTF8');
          //选为 推荐商家
        if($_GET['recommend']=='no'){
            $sql="update shop set recommend=0 where shopid=".$_GET['shopid'];
            mysql_query($sql);
        }else if($_GET['recommend']=='ok'){
            $sql="update shop set recommend=1 where shopid=".$_GET['shopid'];
            mysql_query($sql);
        }
           //选择精选商家
        if($_GET['jingxuan']=='no'){
            if($_SESSION['name'] == '') {
                echo "<script>alert('未知错误，请联系开发者')</script>";
            } else {
              $fp = fopen("logs/a.txt","a+");
              $msg = "账号id：" . $_SESSION['name'] . "  操作时间：" . date("Y-m-d H:i:s") . "  操作状态：" . "关闭" . "  ip地址：" . $_SERVER["REMOTE_ADDR"] . " 店铺id：" . $_GET['shopid'] . "\r\n";
              fputs($fp,$msg);
              fclose($fp);
              $sql="update shop set jingxuan=0 where shopid=".$_GET['shopid'];
              mysql_query($sql);
            }
        }else if($_GET['jingxuan']=='ok'){
            if($_SESSION['name'] == '') {
                echo "<script>alert('未知错误，请联系开发者')</script>";
            } else {
              $fp = fopen("logs/a.txt","a+");
              $msg = "账号id：" . $_SESSION['name'] . "  操作时间：" . date("Y-m-d H:i:s") . "  操作状态：" . "开启" . "  ip地址：" . $_SERVER["REMOTE_ADDR"] . " 店铺id：" . $_GET['shopid'] . "\r\n";
              fputs($fp,$msg);
              fclose($fp);
              $sql="update shop set jingxuan=1 where shopid=".$_GET['shopid'];
              mysql_query($sql);
            }
        }
      
      //查询厂商列表
      $ren="1";
      $sex="0";
      $perNumber=20; //每页显示的记录数
      $page=$_GET['page']; //获得当前的页面值


      $categroyid = '';
      $cityidID = '';
      if(isset($_GET['categroyid']) && $_GET['categroyid'] != '0' ){
        $categroyid = ' shop.leimu = "'.$_GET['categroyid'].'"';
      }
      if(isset($_GET['cityid']) && $_GET['cityid'] != '0' ){
        $cityidID = ' shop.city = "'.$_GET['cityid'].'"';
      }

      if($_REQUEST[keywords]!=""){
          if($categroyid != ''){
            $categroyid.= ' and ';
          }
          if($cityidID != ''){
            $cityidID.= ' and ';
          }

          $count=mysql_query("select count(*) from shop where  jingxuan=1 and ".$categroyid.$cityidID." (name like '%".$_REQUEST[keywords]."%'  OR  shop.tel LIKE '%".$_REQUEST[keywords]."%' OR shop.phone LIKE '%".$_REQUEST[keywords]."%') ");
      }else{
        if($categroyid != '' || $cityidID != ''){
            if($categroyid != ''){
                $categroyid= ' where jingxuan=1 and '.$categroyid;
              }

            if($cityidID != ''){
              if($categroyid == ''){
                   $cityidID= ' where  jingxuan=1 and '.$cityidID;

              }else{
                $cityidID= ' and '.$cityidID;
              }
            }
            $count =  mysql_query("select count(*) from shop ".$categroyid.$cityidID);
        }else{
            $count =  mysql_query("select count(*) from shop where  jingxuan=1 ");
        }
        

      }

      //获得记录总数
      $rs=mysql_fetch_array($count); 
      $totalNumber=$rs[0];
      $totalPage=ceil($totalNumber/$perNumber); //计算出总页数

      if (!isset($page)) {
        $page=1;
      } //如果没有值,则赋值1
      $startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的

      $categroyid = '';
      $cityidID = '';
      if(isset($_GET['categroyid']) && $_GET['categroyid'] != '0' ){
        $categroyid = ' shop.leimu = "'.$_GET['categroyid'].'"';
      }
      if(isset($_GET['cityid']) && $_GET['cityid'] != '0' ){
        $cityidID = ' shop.city = "'.$_GET['cityid'].'"';
      }
      if($_REQUEST[keywords]!=""){   
        $rert30=mysql_query("select * from shop where   jingxuan=1 and  ".$categroyid.$cityidID." (name like '%".$_REQUEST[keywords]."%'   OR  shop.tel LIKE '%".$_REQUEST[keywords]."%' OR shop.phone LIKE '%".$_REQUEST[keywords]."%') order by shopid desc limit $startCount,$perNumber");
      }else{
         if($categroyid != '' || $cityidID != ''){
            if($categroyid != ''){
                $categroyid= ' where jingxuan=1 and '.$categroyid;
              }

            if($cityidID != ''){
              if($categroyid == ''){
                   $cityidID= ' where  jingxuan=1 and '.$cityidID;

              }else{
                $cityidID= ' and '.$cityidID;
              }
            }

            $rert30=mysql_query("select * from shop ".$categroyid.$cityidID." order by shopid desc limit $startCount,$perNumber");
        }else{
            $rert30 =  mysql_query("select * from shop where  jingxuan=1 ");
        }
        
      }

      while($sdg30=mysql_fetch_array($rert30)){
        $ads=mysql_query("select * from ad where shopid='".$sdg30[shopid]."'");
        $wad=mysql_fetch_array($ads);

        $count2=mysql_query("select count(*) from goods where  shopid='".$sdg30[shopid]."' ");
        
      // 分类$sdg30[leimu]
        $query=mysql_query("select * from categroy where cateid='".$sdg30[leimu]."'");
        $categroy=mysql_fetch_assoc($query);
      // 分类 end

      //获得商品记录
        $rs3=mysql_fetch_array($count2); 
        $totalNumber=$rs3[0];

        ?>

  <tr>

    <td scope="col">
      <input type="checkbox" name="checkbox[]" id="checkbox" class="checkbox" value="<?php echo $sdg30[shopid];?>"/></td>
       <td  scope="col">
        <div class="youse">
        <a href="?check=1&shopid=<?php echo $sdg30[shopid];?>">是</a>
        </div>
        <div class="youse2">
          <a href="?check=2&shopid=<?php echo $sdg30[shopid];?>">否</a>
        </div>

       </td>
       <td  scope="col">
          <?php if ($sdg30[check]==0) { ?>
              待审核
          <?php } ?>
          <?php if($sdg30[check]==1){ ?>
              已通过
          <?php }elseif ($sdg30[check]==2) { ?>
              未通过
          <?php } ?>
       </td>
       <td  scope="col">
        <img src="<?php echo $sdg30[jingxuanImg];?>"  width="300px"  height="auto">
      </td>
      <td  scope="col"><?php echo $sdg30[tel];?></td>
      <td  scope="col"><?php echo $sdg30[name];?></td>
      <td  scope="col"><?php echo $sdg30[tel];?></td>
      <td  scope="col"><?php echo $sdg30[address];?></td>
      <?php
      $count2=mysql_query("select * from city where  id='".$sdg30[city]."' ");
      $city=mysql_fetch_array($count2); 
      ?>
      <td  scope="col"><?php echo $city[city];?><?php echo $sdg30[quyu];?></td>
      <td  scope="col"><?php echo $categroy[name];?></td>
      <td  scope="col"><?php echo $totalNumber;?></td>
      
       <td  scope="col">
        <?php if ($sdg30[recommend]==1) {
          echo "是";
        }else{
          echo "否";
        } ?>
      </td>
      <td  scope="col">
      <div class="youse2"><a href="addshop.php?id=<?php echo $sdg30[shopid];?>">编辑商家</a></div> 
      <div class="youse"><a href="goods2.php?shopid=<?php echo $sdg30[shopid];?>">管理商品</a></div>
      <div class="youse2"><a href="shopyouhui.php?shopid=<?php echo $sdg30[shopid];?>">商家优惠券</a></div>
      <div class="youse2"><a href="addjingxuan_shop_tu.php?id=<?php echo $sdg30[shopid];?>">精选广告图</a></div>
<!--         <?php  
        if($wad!=false){ ?>
        <div class="youse"><a href="?cancel=ok&id=<?php echo $wad[id];?>">取消广告</a></div><?php 
      }else{?>
      <div class="youse2"><a href="addad.php?shopid=<?php echo $sdg30[shopid];?>">选为广告</a></div>
      <?php } ?> -->


       <?php
      if($sdg30[recommend]==1){ ?>
      <div class="youse"><a href="?recommend=no&shopid=<?php echo $sdg30[shopid];?>&id=<?php echo $wad[id];?>">取消推荐</a></div><?php 
    }else if($sdg30[recommend]==0){?>
    <div class="youse2"><a href="?recommend=ok&shopid=<?php echo $sdg30[shopid];?>">选为推荐</a></div>
    <?php } ?>

     <?php
      if($sdg30[jingxuan]==1){ ?>
      <div class="youse"><a href="?jingxuan=no&shopid=<?php echo $sdg30[shopid];?>&id=<?php echo $wad[id];?>">取消精选</a></div><?php 
    }else if($sdg30[jingxuan]==0){?>
    <div class="youse2"><a href="?jingxuan=ok&shopid=<?php echo $sdg30[shopid];?>">选为精选</a></div>
    <?php } ?>

      <?php
        if($sdg30[open]==1){ ?>
        <div class="youse">
        <a href="?open=0&shopid=<?php echo $sdg30[shopid];?>">停业</a>
        </div>
      <?php }else if($sdg30[open]==0){?>
      <div class="youse2">
      <a href="?open=1&shopid=<?php echo $sdg30[shopid];?>">营业</a>
      </div>
      <?php } ?>
  </td>
</tr>

<?php }?>
</table>
</form>
<!-- END TABULAR DATA EXAMPLE -->



<div class="grid_12">

  <div class="clearfix">
      <input  type="button" value="删除选中"  class="submit del" />
      <input  type="button" value="一键审核通过"  class="passall submit" />
  </div>

  <ul id="pagination">



    <?php  

    if ($page > 1) { //上一页 ?>
    <li><a     href="?page=1&keywords=<?php echo $_REQUEST[keywords]; ?>&classify=<?php echo $_REQUEST[classify]; ?>&cityid=<?php echo  $_REQUEST[cityid];?>&categroyid=<?php echo $_REQUEST[categroyid]; ?>">首页</a></li>
    <li><a     href="?page=<?php echo ($page-1); ?>&keywords=<?php echo $_REQUEST[keywords]; ?>&classify=<?php echo $_REQUEST[classify]; ?>&cityid=<?php echo  $_REQUEST[cityid];?>&categroyid=<?php echo $_REQUEST[categroyid]; ?>">上一页</a></li>
    <?php }

    ?>

    <li class="active"><?php echo $page;?></li>

    <?php



    if ($_GET[page]!=$totalPage) { //下一页 ?>
    <li><a     href="?page=<?php echo ($page+1); ?>&keywords=<?php echo $_REQUEST[keywords]; ?>&classify=<?php echo $_REQUEST[classify]; ?>&cityid=<?php echo  $_REQUEST[cityid];?>&categroyid=<?php echo $_REQUEST[categroyid]; ?>">下一页</a></li>
    <?php }

    if ($totalPage>1) { //下一页 ?>
    <li><a     href="?page=<?php echo $totalPage; ?>&keywords=<?php echo $_REQUEST[keywords]; ?>&classify=<?php echo $_REQUEST[classify]; ?>&cityid=<?php echo  $_REQUEST[cityid];?>&categroyid=<?php echo $_REQUEST[categroyid]; ?>">尾页</a></li>

    <?php }?>
    <input type="text" class="text skip_val" style="width: 20px;height:12px;margin:0 5px;"><button class="submit skip">跳转</button>

  </ul>

</div>           







</div>
<input type="hidden" id="shopid" value="<?php echo $_REQUEST[shopid]; ?>">
<!-- end content wrap -->


</body>
<script type="text/javascript">

  var shopid=$('#shopid').val();
  function add(){
    window.location.href="addshop.php?shopid="+shopid;
  }
  var cityVal = $('.citys').val();
  
  // 查询社区
  $('.citys').change(function(){
    var categroyid = $('.categroys').val();
    var cityid = $(this).val();
    window.location.href="jingxuan_shop.php?cityid="+cityid+"&categroyid="+categroyid;
  });
  // 查询社区 end
  
  // 查询分类
  $('.categroys').change(function(){
    var cityid = $('.citys').val();
    var categroyid = $(this).val();
    window.location.href="jingxuan_shop.php?cityid="+cityid+"&categroyid="+categroyid;
  });
  // 查询分类 end

  // 一键审核通过
  $('.passall').click(function(){
      var shopid = '';
      $(".checkbox").each(function(){
          if ($(this).prop("checked")) {
              shopid += ','+$(this).val();
          };
      });
      shopid = shopid.substring(1);
      window.location.href = 'jingxuan_shop.php?act=passall&shopids='+shopid;
  })
  // 一键审核通过 end


  // 删除 
  $('.del').click(function(){
    $('#form').submit();
  })
  // 删除 end

  // 页面跳转 
  $('.skip').click(function(){
    var page = $('.skip_val').val();
    var url = "jingxuan_shop.php?page="+page+"&keywords=<?php echo $_REQUEST[keywords]; ?>&classify=<?php echo $_REQUEST[classify]; ?>&cityid=<?php echo  $_REQUEST[cityid];?>&categroyid=<?php echo $_REQUEST[categroyid]; ?>"
    // var url = "jingxuan_shop.php?page="+page;
    window.location.href = url;
  })
  // 页面跳转 end
</script>
</html>
